package com.fjp.heartguard.app.base

import android.content.res.Resources
import android.os.Bundle
import android.widget.ImageView
import androidx.databinding.ViewDataBinding
import com.fjp.heartguard.R
import com.fjp.heartguard.app.eventViewModel
import com.fjp.heartguard.app.ext.dismissLoadingExt
import com.fjp.heartguard.app.ext.showLoadingExt
import com.gyf.immersionbar.ImmersionBar
import me.hgj.jetpackmvvm.base.activity.BaseVmDbActivity
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.jessyan.autosize.AutoSizeCompat


abstract class BaseActivity<VM : BaseViewModel, DB : ViewDataBinding> : BaseVmDbActivity<VM, DB>() {

    abstract override fun initView(savedInstanceState: Bundle?)

    override fun initImmersionBar() {
        ImmersionBar.with(this).init()
        findViewById<ImageView>(R.id.backIv)?.setOnClickListener {
            finish()
        }
    }

    /**
     * 创建liveData观察者
     */
    override fun createObserver() {
        eventViewModel.exitApp.observeInActivity(this){
            finish()
        }
    }

    /**
     * 打开等待框
     */
    override fun showLoading(message: String) {
        showLoadingExt(message)
    }

    /**
     * 关闭等待框
     */
    override fun dismissLoading() {
        dismissLoadingExt()
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(Bundle())
    }

    /* */
    /**
     * 在任何情况下本来适配正常的布局突然出现适配失效，适配异常等问题，只要重写 Activity 的 getResources() 方法
     */
//    override fun getResources(): Resources {
//        AutoSizeCompat.autoConvertDensityOfGlobal(super.getResources())
//        return super.getResources()
//    }
}